package edu.uic.kott.fragments;

import edu.uic.keyoutcomestrackertool.R;
import edu.uic.kott.activities.TrackKeyOutcomes;
import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class TrackOptions extends Fragment implements OnClickListener {

	Button attendanceButton;
	Button studySessionsButton;
	Button testsButton;
	
	public static String attendanceFragment;
	public static String studySessionsFragment;
	public static String activitiesFragment;
	
	FragmentManager fragmentManager;
	FragmentTransaction fragmentTransaction;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		attendanceFragment = "ATTENDANCE_FRAGMENT";
		studySessionsFragment = "STUDY_SESSIONS_FRAGMENT";
		activitiesFragment = "ACTIVITIES_FRAGMENT";
		
		fragmentManager = getFragmentManager();
		
		View track_options_view = inflater.inflate(R.layout.track_options, container, false);
		
		attendanceButton = (Button) track_options_view.findViewById(R.id.track_attendance_button);
		attendanceButton.setOnClickListener(this);
		
		studySessionsButton = (Button) track_options_view.findViewById(R.id.track_study_sessions_button);
		studySessionsButton.setOnClickListener(this);
		
		testsButton = (Button) track_options_view.findViewById(R.id.track_tests_button);
		testsButton.setOnClickListener(this);
		
		return track_options_view;
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		
		TrackAttendance trackAttendance = new TrackAttendance();
		TrackStudySessions trackStudySessions = new TrackStudySessions();
		TrackActivities trackActivities = new TrackActivities();
		Log.i("date", TrackKeyOutcomes.activeDate);
		
		if (id == R.id.track_attendance_button) {
			fragmentTransaction = fragmentManager.beginTransaction();
			fragmentTransaction.replace(R.id.track_view, trackAttendance, attendanceFragment);
			fragmentTransaction.addToBackStack(attendanceFragment);
			fragmentTransaction.commit();
			TrackKeyOutcomes.attendanceVisible = true;
		}
		else if (id == R.id.track_study_sessions_button) {
			fragmentTransaction = fragmentManager.beginTransaction();
			fragmentTransaction.replace(R.id.track_view, trackStudySessions, studySessionsFragment);
			fragmentTransaction.addToBackStack(studySessionsFragment);
			fragmentTransaction.commit();
			TrackKeyOutcomes.studySessionsVisible = true;
		}
		else if (id == R.id.track_tests_button) {
			fragmentTransaction = fragmentManager.beginTransaction();
			fragmentTransaction.replace(R.id.track_view, trackActivities, activitiesFragment);
			fragmentTransaction.addToBackStack(activitiesFragment);
			fragmentTransaction.commit();
			TrackKeyOutcomes.activitiesVisible = true;
		}
	}
}
